﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

public partial class createnewindex : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection sc = new SqlConnection(Application["sqlconnection"].ToString());
        sc.Open();
        SqlCommand com_getsort = sc.CreateCommand();
        com_getsort.CommandText = "SELECT Name from Sort";
        SqlDataReader sd=com_getsort.ExecuteReader();
        for (int i = 0; i < sd.FieldCount; i++)
        {
            DropDownList1.Items.Add(sd[i].ToString());
        }
        sc.Close();
        CKEditorControl1.FontSizes = "large";

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string title = TextBox1.Text+DateTime.Now.ToLongDateString()+DateTime.Now.ToLongTimeString().Replace(":","s")+".txt";
        string path=AppDomain.CurrentDomain.BaseDirectory +"\\index_new\\"+ title;
        try
        {    //添加简易文本编辑器
            FileStream aFile = new FileStream(path, FileMode.CreateNew);
            StreamWriter write = new StreamWriter(aFile);
            write.Write("<title>"+TextBox1.Text+"</title>");
            write.WriteLine();
            write.Write("<sort>" + DropDownList1.Text + "</sort>");
            write.WriteLine();
            write.Write(DateTime.Now.ToString());
            write.WriteLine();
            write.Write(CKEditorControl1.Value);write.Close();
            //Response.Write("<script language=javascript>alert=('索引已成功提交，请等待审核！')</script>");
           
            Response.Redirect("index.aspx");
            
        }
        catch (IOException ee)
        {
           
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("index.aspx",true);
    }
}